<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="author" content="BaiYY"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/pages.css"/>
    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/pages.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/page2.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.validate.min.js"></script>
</head>
<body>
    <div class="right-sidebar" style="max-width: 1200px;position: relative">
        <ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
            <li role="presentation"><a href="myNext.html">下级详情</a></li>
            <if condition='$review eq 1'>
                <li role="presentation"><a href="myNextCheck.html">下级审核</a></li>
            </if>
            <li role="presentation"><a href="myNextSearch.html">下级查询</a></li>
            <if condition='$role lt $player'>
                <li role="presentation" class="active" id="playerole"><a href="playerSearch.html">{:L(GAME_SETTING_PLAYER)}</a></li>
            </if>
        </ul>
        <section>
            <div class="input-group">
                <input type="text" class="form-control" placeholder="请输入玩家ID" name="uid" id="uid">
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button" id="btn">&emsp;查看&emsp;</button>
                </span>
            </div>
            <section class="table-responsive">
                <table class="table" style="border: 1px solid #ddd;">
                    <thead>
                        <tr>
                            <th>游戏UID</th>
                            <th>微信昵称</th>
                            <th>剩余{:L(GAME_RESOURCE)}</th>
                            <th>剩余金币</th>
                            <th>注册时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="dataList"></tbody>
                </table>
            </section>
            <div id="sub_tips" style="top: 180px;">
                <ul>
                    <li id="special"><span data-toggle="modal" data-target="#kmyModal">{:L(GAME_SETTING_SPECIAL)}</span></li>
                    <li id="openAgent"><span id='setRole' onclick='onClick()'>{:L(GAME_SETTING_AGENT)}</span></li>
                </ul>
            </div>
        </section>
        <div class="modal fade" id="kmyModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabelk">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="exampleModalLabelk">专场图标显示设置</h4>
                    </div>
                    <div class="modal-body" style="padding-top: 0">
                        <div class="row" >
                            <div class="col-md-12">
                                <h3>说明</h3>
                                <p>该设置可控制客户端是否显示{:L(GAME_SESSION)}图标</p>
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="input-group">
                                            <span class="input-group-addon">游戏ID&emsp;</span>
                                            <input type="text" class="form-control" name="uid" id="uidd" disabled="true">
                                        </div>
                                        <div class="input-group">
                                            <span class="input-group-addon">{:L(GAME_SESSION)}图标</span>
                                            <div class="form-control">
                                                <input type="radio" name="privilege" value="1" id="privilege1">显示
                                                <input type="radio" name="privilege" value="0" id="privilege0">不显示
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" id="pbtn">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            var listData = $("#sub_tips>ul>li");
            for(var i=0;i<listData.length;i++) {
//                console.log($(listData).eq(i).text());
                if($(listData).eq(i).text() == '' || $(listData).eq(i).text() == null) {
                    $(listData).eq(i).hide();
                }
            }
        })
        $("#btn").on("click",function(){
            var user_id = "<?php echo session('adminTel');?>";
            var uid = $.trim($("#uid").val());
            if(uid == '' || uid == null){
                alert("请输入要查询的代理ID!");
                return false;
            }else if(isNaN($.trim(uid))){
                alert("代理ID是数字!");
                window.location.href="{:U('Admin/Main/myNextSearch')}";
                return false;
            }else if(uid == user_id) {
                alert("抱歉，不能输入自己的ID");
                window.location.href="{:U('Admin/Main/myNextSearch')}";
            }
            $.ajax({
                type:"get",
                url:"{:U('Admin/Main/playerSearchh')}?uid="+uid,
                success:function(data){
//                    console.log(data);
                    if(data == 'cannot') {
                        alert("抱歉，该账号已是代理了！");
                        window.location.href="{:U('Admin/Main/playerSearch')}";
                    }else if(data == 'unexist') {
                        alert("抱歉！该ID不在游戏中");
                        window.location.href="{:U('Admin/Main/playerSearch')}";
                    }else{
                        var str = '';
                        str += '<tr><td class="uid">'+data._id+"</td><td>"+data.info.name+"</td><td>"+data.status.card+"</td><td>"+data.status.coin+"</td><td>"+getLocalTime(data.info.createTime)+"</td><td><button class='btn btn-primary' id='setHandel' onclick='setHandel()'>设置</button></td></tr>";
                        $("#dataList").html(str);
                        $("#uidd").val(data._id);
                        if(data.hasOwnProperty('privilege') && data.privilege == 1){
                            $("#privilege1").attr('checked',true);
                        }else{
                            $("#privilege0").attr('checked',true);
                        }
                    }
                }
            })
        });
        function onClick() {
            var uid = $("td.uid").text();
            $.ajax({
                type:"get",
                url:"{:U('Admin/Main/myNextRole')}?uid="+uid,
                success:function (data) {
                    console.log(data);
//                    if(data == 'error') {
//                        alert("设置失败！");
//                        window.location.href="{:U('Admin/Main/playerSearch')}";
//                    }else if(data.state == 'success'){
//                        alert("开通成功，代理的密码是："+data.password);
//                        window.location.href="{:U('Admin/Main/playerSearch')}";
//                    }
                }
            })
        }
        $("#pbtn").on("click",function () {
            var privilege = $("input[name='privilege']:checked").val();
            var uid = $("#uidd").val();
            $.ajax({
                type:"post",
                url:"{:U('Admin/Main/playerPriv')}",
                dataType:"json",
                data:{"uid":uid,"privilege":privilege},
                success:function(data) {
                    if(data == 'success') {
                        alert("开通成功!");
                        $("#kmyModal").hide();
                        $(".modal-backdrop").hide();
                    }else if(data == 'error') {
                        alert("开通失败！");
                        window.location.href="{:U('Admin/Main/playerSearch')}";
                    }
                }
            })
        })
        function setHandel() {
            $("#sub_tips").toggle();
            $("#sub_tips").on("click",function () {
                $(this).hide();
            })
        }
    </script>
</body>
</html>